package com.jmu.shoppingcart;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class Store {
    private static int ID=0;
    Map<Commodity,Integer> commoditys= new LinkedHashMap<>();
    public void add(String name,double price,int number){
        Commodity commodity=new Commodity(name,price,ID++);
        commoditys.put(commodity,number);
    }

    public void showStory(){
        System.out.println("ID\t\t\tname\t\t\t\tprice\t\t\t\tnumber");
        commoditys.forEach((K,V)->{
            System.out.println(K+"\t"+V);
        });
    }
    public Commodity findCommodity(String name) {
        for (Commodity commodity : commoditys.keySet()) {
            if(commodity.getName().equals(name)){
                return commodity;
            }
        }
        return null;
    }

    public int getRepertory(Commodity commodity) {
        return commoditys.get(commodity);
    }

    public void update(Commodity commodity,int number) {
        commoditys.put(commodity,commoditys.get(commodity)-number);
    }
}
